package com.bdqn.hospital.controller;

import com.alibaba.fastjson.JSON;
import com.bdqn.hospital.pojo.Room;
import com.bdqn.hospital.pojo.Schedule;
import com.bdqn.hospital.pojo.SysUsers;
import com.bdqn.hospital.service.impl.RoomServiceImpl;
import com.bdqn.hospital.service.impl.ScheduleServiceImpl;
import com.bdqn.hospital.service.impl.SysUsersServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.List;

/**
 * @version : 1.0
 * @Author :guogd
 * @createTime: 2023/03/01 14:39
 * @Description: com.bdqn.hospital.controller
 */
@Controller
@RequestMapping("Schedule")
public class ScheduleController {
    /**
     * 医生排期Controller
     */

    @Autowired
    private ScheduleServiceImpl scheduleService;
    @Autowired
    private SysUsersServiceImpl sysUsersService;
    @Autowired
    private RoomServiceImpl roomService;

    @ResponseBody
    @RequestMapping("getDoctorInfo")
    public List<SysUsers> getDoctorInfo(Integer departmentId,Integer sign){
        List<Schedule>  scheduleList= scheduleService.getByDepartmentIdAndSign(departmentId, sign);
        List<SysUsers> doctorInfo=new ArrayList<>();
        for (Schedule schedule : scheduleList) {
            doctorInfo.add(sysUsersService.getById(schedule.getUserId()));
        }
        return doctorInfo;
    }

    @ResponseBody
    @RequestMapping("getRoomInfo")
    public String getRoomInfo(Integer userId,Integer departmentId,Integer sign){
        List<Schedule>  scheduleList= scheduleService.getByDepartmentIdAndSign(departmentId, sign);
        Room room = new Room();
        for (Schedule schedule : scheduleList) {
            if(schedule.getUserId()==userId){
                room = roomService.getById(schedule.getRoomId());
            }
        }
        return  JSON.toJSONString(room);
    }
    @ResponseBody
    @RequestMapping("getScheduleId")
    public String getScheduleId(Integer userId){
        Schedule schedule = scheduleService.getByUserId(userId);
        return  JSON.toJSONString(schedule);
    }
}
